﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FJERP.BLL;
using FJERP.Model;

namespace FJERP
{
    public partial class CommodityShow : System.Web.UI.Page
    {
        ProductBLL bll = new ProductBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
          if(!IsPostBack)
          {
              PagerLoad();
              xiala();
          }
        }

        protected void PagerLoad()
        {
            this.AspNetPager1.RecordCount = bll.Product_Count();//设置总行数
            this.AspNetPager1.PageSize = 3;//设置每页显示行数
            this.Repeater1.DataSource = bll.Product_show(3,this.AspNetPager1.CurrentPageIndex);//设置数据源
            this.Repeater1.DataBind();//绑定数据
            Label1.Text = bll.Product_Count().ToString();
        }

        protected void xiala()
        {
            this.DropDownList2.DataSource = bll.Product_Type_Show();
            //显示"请选择"
            ListItem list = new ListItem();
            this.DropDownList2.DataValueField = "Product_Type_Id";//绑定ID值
            this.DropDownList2.DataTextField = "Product_Type_Name";//显示字段
            this.DropDownList2.DataBind();//绑定数据源
            list.Text = "----请选择----";//绑定的选择
            list.Value = "0";//赋值
            list.Selected = true;
            DropDownList2.Items.Add(list);

        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string name = e.CommandName;
            string sid = e.CommandArgument.ToString();
            switch(name)
            {
                case"Del":
                    if(bll.Del(Convert.ToInt32(sid))>0)
                    {
                        Response.Write("<script>alert('删除成功!!!')</script>");
                        PagerLoad();
                    }
                    else
                    {
                        Response.Write("<script>alert('删除失败!!!')</script>");
                    }
                    break;
                case "Upt":
                    Response.Redirect("CommodityEdit.aspx?id=" + sid);
                    break;
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            PagerLoad();
            xiala();
        }

        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            this.AspNetPager1.RecordCount = bll.Product_Count();
            this.AspNetPager1.PageSize = 3;
            this.Repeater1.DataSource = bll.Product_show_Sel(3, this.AspNetPager1.CurrentPageIndex, this.Product_Name.Value, this.Product_Modelspe.Value, Convert.ToInt32(this.DropDownList2.SelectedValue));
            this.Repeater1.DataBind();
        }
    }
}